package com.helper;

import com.dto.RowValidateResult;
import com.filter.chain.StudentChcke;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.List;
import java.util.Map;

public class Dome {
    public static void main(String[] args) throws FileNotFoundException{
        //类转化器
//        BeanGenerator<Student> generator = new BeanGenerator();
//        Map<String, List<Object[]>> map = ExcelUtils.readTomap(new FileInputStream("G:\\Excel练习\\写入信息.xls"));
//        for (Map.Entry<String, List<Object[]>> entry : map.entrySet()) {
//            List<Object[]> value = entry.getValue();
//            for (Object[] objects : value) {
//                Student student = generator.generateBean(Student.class, objects);
//                System.out.println(student);
//            }
//        }

        //读取excel所有数据完成类转换
        String[] title = {"编号","姓名","性别","年龄","电话","地址","生日","学历","星座","身份证"};
        ExcelToBeanConvertor<Student> convertor = new ExcelToBeanConvertor();
        Map<String,List<Student>> map = convertor.readToBeanMap(title, new FileInputStream("G:\\Excel练习\\写入信息.xls"), Student.class);
        for (Map.Entry<String, List<Student>> mp : map.entrySet()) {
            List<Student> value = mp.getValue();
            System.out.println("总条数" + value.size());
            StudentChcke chcke = new StudentChcke();

            List<RowValidateResult> rowValidateResults = chcke.doFilter(value);
            System.out.println(rowValidateResults);
            for (RowValidateResult re : rowValidateResults) {
                System.out.println("错误行" + re.getIndex());
                System.out.println("错误信息" + re.getRows().get(0).getErrmsg());
            }
            System.out.println("错误条数" + rowValidateResults.size());
        }
    }
}